from django.core.exceptions import ValidationError
import os


def image_validate_file_extension(value):
    ext = os.path.splitext(value.name)[1]  
    valid_extensions = ['.jpg', '.jpeg', '.png', '.gif']
    if not ext.lower() in valid_extensions:
        raise ValidationError('Unsupported file extension.')

def image_validate_file_size(value):
    max_size = 5 * 1024 * 1024  # 5MB
    if value.size > max_size:
        raise ValidationError('File too large. Size should not exceed 5 MB.')
    
def video_validate_file_extension(value):
    ext = os.path.splitext(value.name)[1]  
    valid_extensions = ['.mp4', '.avi']
    if not ext.lower() in valid_extensions:
        raise ValidationError('Unsupported file extension.')

def video_validate_file_size(value):
    max_size = 30 * 1024 * 1024  # 30MB
    if value.size > max_size:
        raise ValidationError('File too large. Size should not exceed 30 MB.')